<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Removes and returns a value by key</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ds-map.reduce.html">« Ds\Map::reduce</a></li>
      <li style="float: right;"><a href="ds-map.reverse.html">Ds\Map::reverse »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.ds-map.html">Map</a></li>
    <li>Removes and returns a value by key</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="ds-map.remove" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Ds\Map::remove</h1>
  <p class="verinfo">(PECL ds &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Ds\Map::remove</span> &mdash; <span class="dc-title">Removes and returns a value by key</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-ds-map.remove-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Ds\Map::remove</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$key</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$default</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
    Removes and returns a value by key, or return an optional default value if the key
    could not be found.
  </p>

  <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para">
        Keys of type <span class="type">object</span> are supported.

        If an object implements <span class="classname"><strong class="classname">Ds\Hashable</strong></span>,
        equality will be determined by the object&#039;s <code class="code">equals</code> function.

        If an object does not implement <span class="classname"><strong class="classname">Ds\Hashable</strong></span>,
        objects must be references to the same instance to be considered equal.
    </p>
  </p></blockquote>

  <blockquote class="note"><p><strong class="note">注意</strong>: 
    <p class="para">
        You can also use array syntax to access values by key, eg. <code class="code">$map[&quot;key&quot;]</code>.
    </p>
  </p></blockquote>

  <div class="caution"><strong class="caution">警告</strong>
    <p class="para">
        Be careful when using array syntax. Scalar keys will be coerced to
        integers by the engine. For example, <code class="code">$map[&quot;1&quot;]</code> will attempt
        to access <code class="code">int(1)</code>, while <code class="code">$map-&gt;get(&quot;1&quot;)</code> will
        correctly look up the string key.
    </p>
    <p class="para">
        See <a href="language.types.array.html" class="link">Arrays</a>.
    </p>
  </div>

 </div>


 <div class="refsect1 parameters" id="refsect1-ds-map.remove-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">key</code></dt>

    <dd>

     <p class="para">
        The key to remove.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">default</code></dt>

    <dd>

     <p class="para">
        The optional default value, returned if the key could not be found.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-ds-map.remove-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
    The value that was removed, or the <code class="parameter">default</code>
    value if provided and the <code class="parameter">key</code> could not be found in the map.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-ds-map.remove-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   <span class="classname"><a href="class.outofboundsexception.html" class="classname">OutOfBoundsException</a></span> if the key could not be found
   and a default value was not provided.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-ds-map.remove-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-4103">
   <p><strong>示例 #1 <span class="function"><strong>Ds\Map::remove()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$map&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;\</span><span style="color: #0000BB">Ds</span><span style="color: #007700">\</span><span style="color: #0000BB">Map</span><span style="color: #007700">([</span><span style="color: #DD0000">"a"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"b"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"c"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">]);<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$map</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">remove</span><span style="color: #007700">(</span><span style="color: #DD0000">"a"</span><span style="color: #007700">));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;&nbsp;1<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$map</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">remove</span><span style="color: #007700">(</span><span style="color: #DD0000">"e"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">));&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;10&nbsp;(default&nbsp;used)<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(1)
int(10)
</pre></div>
   </div>
  </div>
 </div>



</div></div></div></body></html>